﻿/// <reference path="typings/jquery.d.ts" />
import ajaxOptions = require("AjaxCallsOptions");
import config = require("Configuration");
import dataAccess = require("Data-access");
import application = require("WindowExtensions");

export class Trailers extends kendo.data.ObservableObject {

    constructor() {
        super();
        super.init(this);
    }

    private _instance = this;

    show(e) {
        var options = new ajaxOptions.AjaxOptions();
        options.url = config.Configuration.getTrailersUrl;
        options.requestType = "GET";
        options.dataType = "JSON";

        dataAccess.callService(options, this._instance, this.fnGetTrailerCallBack);
    }
    
    fnGetTrailerCallBack(model: kendo.data.ObservableObject, result: ajaxOptions.AjaxOptionsCallbackInput) {
        if (result.success !== true) {
            alert("Error generated in fnGetTrailerCallBack");
        } else {
            var trailerTemplate = kendo.template($("#mt-trailers-view #mt-tmpl-trailers").html());
            var scrollView = $("#mt-trailers-view #mt-trailer-scrollview");
            var dataKendo: kendo.mobile.ui.ScrollView = scrollView.data('kendoMobileScrollView');
            dataKendo.content(kendo.render(trailerTemplate, result.data));       
        }
    }
}

var appInit = application.getAppInitProperty();
appInit.TrailersInit = () => {
    var viewModel = new Trailers();
    kendo.bind($("#mt-trailers-view"), viewModel);
} 